import json
import socket

import requests
from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.


def index(request):
    #接受post 参数，并且调用Java的接口返回数据
    request_body = json.dumps(json.loads(request.body))
    # http://395db05950ae4ad6ac2977ff98c45410.apigw.sx-region-2.sgic.sgcc.com.cn/fhyc_test_a
    datas = {"app_secret": "20330eef54d9444caf9bf21cbc66276a",
             "app_key": "08658996a05f40a286836c17be8deebd",
             "api_id": "67c3d8753ea929b2e0b91fdf4f73a58a",
             "rquest_url": "http://395db05950ae4ad6ac2977ff98c45410.apigw.sx-region-2.sgic.sgcc.com.cn/fhyc_test_a",
             "request_method": "GET",
             "request_body": request_body}
    headers = {
        "Content-Type": "application/json"
    }
    myaddr = socket.gethostbyname(socket.getfqdn(socket.gethostname( )))
    print(myaddr)
    r = requests.post('http://'+myaddr+':8899/dataService/post', data=json.dumps(datas), headers=headers)
    return HttpResponse(r.content)